namespace SmartSoft.Lists
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.SystemForms;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDmTkEditor : FormListEditor
    {
        private IContainer components;
        private LabelControl lblTen_Tk;
        private LabelControl lblTen_Tk_E;
        private LabelControl lblTk;
        private LabelControl lblTk_Me;
        private TextControl txtTen_Tk;
        private TextControl txtTen_Tk_E;
        private TextControl txtTk;
        private TextControl txtTen_Tk_Me;
        private TextSearch txtTk_Me;

        public FormDmTkEditor()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDmTkEditor));
            this.txtTk = new SmartSoft.Controls.TextControl();
            this.lblTk = new SmartSoft.Controls.LabelControl();
            this.txtTen_Tk = new SmartSoft.Controls.TextControl();
            this.lblTen_Tk = new SmartSoft.Controls.LabelControl();
            this.txtTen_Tk_E = new SmartSoft.Controls.TextControl();
            this.lblTen_Tk_E = new SmartSoft.Controls.LabelControl();
            this.txtTk_Me = new SmartSoft.Controls.TextSearch();
            this.lblTk_Me = new SmartSoft.Controls.LabelControl();
            this.txtTen_Tk_Me = new SmartSoft.Controls.TextControl();
            this.SuspendLayout();
            // 
            // lblPhan_Loai
            // 
            this.lblPhan_Loai.Location = new System.Drawing.Point(12, 137);
            // 
            // txtMa_Loai1
            // 
            this.txtMa_Loai1.FirstFilter = "Type = \'TK1\'";
            this.txtMa_Loai1.Location = new System.Drawing.Point(123, 134);
            this.txtMa_Loai1.Size = new System.Drawing.Size(155, 20);
            this.txtMa_Loai1.TabIndex = 13;
            // 
            // txtMa_Loai2
            // 
            this.txtMa_Loai2.FirstFilter = "Type = \'TK2\'";
            this.txtMa_Loai2.Location = new System.Drawing.Point(280, 134);
            this.txtMa_Loai2.Size = new System.Drawing.Size(156, 20);
            this.txtMa_Loai2.TabIndex = 14;
            // 
            // txtMa_Loai3
            // 
            this.txtMa_Loai3.FirstFilter = "Type = \'TK3\'";
            this.txtMa_Loai3.Location = new System.Drawing.Point(438, 134);
            this.txtMa_Loai3.Size = new System.Drawing.Size(155, 20);
            this.txtMa_Loai3.TabIndex = 15;
            // 
            // txtTk
            // 
            this.txtTk.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtTk.CheckTextSearched = false;
            this.txtTk.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtTk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTk.Location = new System.Drawing.Point(123, 28);
            this.txtTk.MaxLength = 32;
            this.txtTk.Name = "txtTk";
            this.txtTk.OldValue = null;
            this.txtTk.Size = new System.Drawing.Size(155, 20);
            this.txtTk.TabIndex = 0;
            this.txtTk.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtTk.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtTk.Value = ((object)(resources.GetObject("txtTk.Value")));
            // 
            // lblTk
            // 
            this.lblTk.AutoSize = true;
            this.lblTk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTk.Location = new System.Drawing.Point(12, 31);
            this.lblTk.Name = "lblTk";
            this.lblTk.Size = new System.Drawing.Size(53, 14);
            this.lblTk.TabIndex = 4;
            this.lblTk.Text = "Tài khoản";
            // 
            // txtTen_Tk
            // 
            this.txtTen_Tk.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Tk.CheckTextSearched = false;
            this.txtTen_Tk.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtTen_Tk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Tk.Location = new System.Drawing.Point(123, 50);
            this.txtTen_Tk.MaxLength = 128;
            this.txtTen_Tk.Name = "txtTen_Tk";
            this.txtTen_Tk.OldValue = null;
            this.txtTen_Tk.Size = new System.Drawing.Size(470, 20);
            this.txtTen_Tk.TabIndex = 1;
            this.txtTen_Tk.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Tk.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtTen_Tk.Value = ((object)(resources.GetObject("txtTen_Tk.Value")));
            // 
            // lblTen_Tk
            // 
            this.lblTen_Tk.AutoSize = true;
            this.lblTen_Tk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTen_Tk.Location = new System.Drawing.Point(12, 53);
            this.lblTen_Tk.Name = "lblTen_Tk";
            this.lblTen_Tk.Size = new System.Drawing.Size(71, 14);
            this.lblTen_Tk.TabIndex = 4;
            this.lblTen_Tk.Text = "Tên tài khoản";
            // 
            // txtTen_Tk_E
            // 
            this.txtTen_Tk_E.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtTen_Tk_E.CheckTextSearched = false;
            this.txtTen_Tk_E.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtTen_Tk_E.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Tk_E.Location = new System.Drawing.Point(123, 72);
            this.txtTen_Tk_E.MaxLength = 128;
            this.txtTen_Tk_E.Name = "txtTen_Tk_E";
            this.txtTen_Tk_E.OldValue = null;
            this.txtTen_Tk_E.Size = new System.Drawing.Size(470, 20);
            this.txtTen_Tk_E.TabIndex = 2;
            this.txtTen_Tk_E.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemDescription;
            this.txtTen_Tk_E.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtTen_Tk_E.Value = ((object)(resources.GetObject("txtTen_Tk_E.Value")));
            // 
            // lblTen_Tk_E
            // 
            this.lblTen_Tk_E.AutoSize = true;
            this.lblTen_Tk_E.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTen_Tk_E.Location = new System.Drawing.Point(12, 75);
            this.lblTen_Tk_E.Name = "lblTen_Tk_E";
            this.lblTen_Tk_E.Size = new System.Drawing.Size(73, 14);
            this.lblTen_Tk_E.TabIndex = 4;
            this.lblTen_Tk_E.Text = "Tên tiếng Anh";
            // 
            // txtTk_Me
            // 
            this.txtTk_Me.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtTk_Me.CheckTextSearched = false;
            this.txtTk_Me.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtTk_Me.EmptyIsValid = true;
            this.txtTk_Me.FieldDisplay = "Ten_Tk";
            this.txtTk_Me.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTk_Me.FoundIsValid = true;
            this.txtTk_Me.Location = new System.Drawing.Point(123, 96);
            this.txtTk_Me.MaxLength = 32;
            this.txtTk_Me.Name = "txtTk_Me";
            this.txtTk_Me.OldValue = null;
            this.txtTk_Me.Size = new System.Drawing.Size(155, 20);
            this.txtTk_Me.TabIndex = 12;
            this.txtTk_Me.TableName = "DMTK";
            this.txtTk_Me.TextDisplay = this.txtTen_Tk_Me;
            this.txtTk_Me.UserTextLength = SmartSoft.AppInstance.TextControlLength.ItemCode;
            this.txtTk_Me.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.All;
            this.txtTk_Me.Value = ((object)(resources.GetObject("txtTk_Me.Value")));
            // 
            // lblTk_Me
            // 
            this.lblTk_Me.AutoSize = true;
            this.lblTk_Me.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTk_Me.Location = new System.Drawing.Point(12, 99);
            this.lblTk_Me.Name = "lblTk_Me";
            this.lblTk_Me.Size = new System.Drawing.Size(70, 14);
            this.lblTk_Me.TabIndex = 4;
            this.lblTk_Me.Text = "Tài khoản mẹ";
            // 
            // txtTen_Tk_Me
            // 
            this.txtTen_Tk_Me.BackColor = System.Drawing.SystemColors.Control;
            this.txtTen_Tk_Me.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Tk_Me.CheckTextSearched = false;
            this.txtTen_Tk_Me.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Tk_Me.Enabled = false;
            this.txtTen_Tk_Me.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Tk_Me.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Tk_Me.Location = new System.Drawing.Point(280, 99);
            this.txtTen_Tk_Me.Name = "txtTen_Tk_Me";
            this.txtTen_Tk_Me.OldValue = null;
            this.txtTen_Tk_Me.Size = new System.Drawing.Size(309, 13);
            this.txtTen_Tk_Me.TabIndex = 13;
            this.txtTen_Tk_Me.UserTextLength = SmartSoft.AppInstance.TextControlLength.None;
            this.txtTen_Tk_Me.UserTrimMode = SmartSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Tk_Me.Value = ((object)(resources.GetObject("txtTen_Tk_Me.Value")));
            // 
            // FormDmTkEditor
            // 
            this.AddTitleText = "Thêm mới tài khoản";
            this.ClientSize = new System.Drawing.Size(610, 166);
            this.Controls.Add(this.txtTk_Me);
            this.Controls.Add(this.lblTen_Tk_E);
            this.Controls.Add(this.lblTen_Tk);
            this.Controls.Add(this.lblTk_Me);
            this.Controls.Add(this.lblTk);
            this.Controls.Add(this.txtTen_Tk_Me);
            this.Controls.Add(this.txtTen_Tk_E);
            this.Controls.Add(this.txtTen_Tk);
            this.Controls.Add(this.txtTk);
            this.EditTitleText = "Sửa tài khoản";
            this.FirstFreeCode = "TK1";
            this.Name = "FormDmTkEditor";
            this.SecondFreeCode = "TK2";
            this.Text = "Them moi tai khoan";
            this.ThirdFreeCode = "TK3";
            this.Controls.SetChildIndex(this.txtTk, 0);
            this.Controls.SetChildIndex(this.txtTen_Tk, 0);
            this.Controls.SetChildIndex(this.txtTen_Tk_E, 0);
            this.Controls.SetChildIndex(this.txtTen_Tk_Me, 0);
            this.Controls.SetChildIndex(this.lblTk, 0);
            this.Controls.SetChildIndex(this.lblTk_Me, 0);
            this.Controls.SetChildIndex(this.lblTen_Tk, 0);
            this.Controls.SetChildIndex(this.lblTen_Tk_E, 0);
            this.Controls.SetChildIndex(this.txtTk_Me, 0);
            this.Controls.SetChildIndex(this.lblPhan_Loai, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai1, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai2, 0);
            this.Controls.SetChildIndex(this.txtMa_Loai3, 0);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (string.IsNullOrEmpty(this.txtTk.Text))
            {
                MessageBox.Show("Chưa nhập số hiệu tài khoản!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Tk.Text))
            {
                MessageBox.Show("Chưa nhập tên tài khoản!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtTen_Tk_E.Text))
            {
                MessageBox.Show("Chưa nhập tên tài khoản tiếng Anh!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (!string.IsNullOrEmpty(this.txtTk_Me.Text))
            {
                DataTable table = SSDataAccess.CheckInUsed(base.LocalFieldName, this.txtTk_Me.Text);
                DataRow row = table.Rows.Find("DMTK");
                if (row != null)
                {
                    table.Rows.Remove(row);
                }
                if (table.Rows.Count != 0)
                {
                    FormCheckDeleted deleted = new FormCheckDeleted();
                    deleted.LocalTable = table;
                    deleted.ShowDialog();
                    return false;
                }
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Tk"] = this.txtTk.Value;
            localCurrentRow["Ten_Tk"] = this.txtTen_Tk.Value;
            localCurrentRow["Ten_Tk_E"] = this.txtTen_Tk_E.Value;
            //localCurrentRow["Tk_Nt"] = this.txtTk_Nt.Value;
            //localCurrentRow["Tk_Bp"] = this.txtTk_Bp.Value;
            //localCurrentRow["Tk_Hd"] = this.txtTk_Hd.Value;
            //localCurrentRow["Tk_Dt"] = this.txtTk_Dt.Value;
            //localCurrentRow["Tk_Kv"] = this.txtTk_Kv.Value;
            //localCurrentRow["Tk_Gt"] = this.txtTk_Gt.Value;
            //localCurrentRow["Tk_Sc"] = this.txtTk_Sc.Value;
            //localCurrentRow["Tk_Km"] = this.txtTk_Km.Value;
            //localCurrentRow["Tk_VAT"] = this.txtTk_VAT.Value;
            localCurrentRow["Tk_Me"] = this.txtTk_Me.Value;
            localCurrentRow["Ten_Tk_Me"] = this.txtTen_Tk_Me.Value;
            localCurrentRow["Ma_Loai1"] = base.txtMa_Loai1.Value;
            localCurrentRow["Ma_Loai2"] = base.txtMa_Loai2.Value;
            localCurrentRow["Ma_Loai3"] = base.txtMa_Loai3.Value;
            DmTkDataAccess access = new DmTkDataAccess();
            if (base.ShowMessage(localCurrentRow, access.SaveRow(base.NewChecked, localCurrentRow)))
            {
                return false;
            }
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtTk.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtTk.Value = base.LocalCurrentRow["Tk"];
            this.txtTen_Tk.Value = base.LocalCurrentRow["Ten_Tk"];
            this.txtTen_Tk_E.Value = base.LocalCurrentRow["Ten_Tk_E"];
            //this.txtTk_Nt.Value = base.LocalCurrentRow["Tk_Nt"];
            //this.txtTk_Bp.Value = base.LocalCurrentRow["Tk_Bp"];
            //this.txtTk_Hd.Value = base.LocalCurrentRow["Tk_Hd"];
            //this.txtTk_Dt.Value = base.LocalCurrentRow["Tk_Dt"];
            //this.txtTk_Kv.Value = base.LocalCurrentRow["Tk_Kv"];
            //this.txtTk_Gt.Value = base.LocalCurrentRow["Tk_Gt"];
            //this.txtTk_Sc.Value = base.LocalCurrentRow["Tk_Sc"];
            //this.txtTk_Km.Value = base.LocalCurrentRow["Tk_Km"];
            //this.txtTk_VAT.Value = base.LocalCurrentRow["Tk_VAT"];
            this.txtTk_Me.Value = base.LocalCurrentRow["Tk_Me"];
            this.txtTen_Tk_Me.Value = base.LocalCurrentRow["Ten_Tk_Me"];
            base.txtMa_Loai1.Value = base.LocalCurrentRow["Ma_Loai1"];
            base.txtMa_Loai2.Value = base.LocalCurrentRow["Ma_Loai2"];
            base.txtMa_Loai3.Value = base.LocalCurrentRow["Ma_Loai3"];
            base.OnShow();
        }
    }
}

